import { defHttp } from '/@/utils/http/axios';
import { BasicFetchResult } from '../model/baseModel';
import {
  LoginParams,
  LoginResultModel,
  GetUserInfoModel,
  GetCaptchaModel,
} from './model/userModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/auth/login',
  Logout = '/auth/logout',
  GetUserInfo = '/auth/get',
  GetMyMenu = '/auth/my-menu',
  GetPermCode = '/auth/my-permission',
  GetCaptcha = '/auth/captcha',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicFetchResult<LoginResultModel>>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: get captcha
 */
export function getCaptcha() {
  return defHttp.post<BasicFetchResult<GetCaptchaModel>>(
    {
      url: Api.GetCaptcha,
    },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.post<BasicFetchResult<GetUserInfoModel>>(
    { url: Api.GetUserInfo },
    { errorMessageMode: 'none' },
  );
}

export function getMyMenus() {
  return defHttp.post({ url: Api.GetMyMenu });
}

export function getPermCode() {
  return defHttp.post<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.post({ url: Api.Logout }, { encrypt: false });
}
